﻿// 结果公示
import React, { useEffect, useState } from 'react';
import { Table, Input, DatePicker, Form, ConfigProvider, Button, Row, Col } from 'antd';
import { getResultPublicity } from '@/services/homePage/homePage';
import zhCN from 'antd/lib/locale/zh_CN';
import moment from 'moment';
import { SearchOutlined } from '@ant-design/icons';
import styles from './index.less';

const layout = {
  labelCol: { span: 8 },
  wrapperCol: { span: 16 },
};

const { RangePicker } = DatePicker;

const ResultPublicityTable: React.FC = () => {
  const [resultPublicityData, setResultPublicityData] = useState([]);
  const [searchCondition, setSearchCondition] = useState({});
  useEffect(() => {
    getResultPublicity(searchCondition)
      .then((resp) => {
        const data = resp.results?.map((item: { id: any }) => {
          return {
            key: item?.id,
            ...item,
          };
        });
        setResultPublicityData(data);
      })
      .catch((error) => {
        throw error;
      });
  }, [searchCondition]);

  const columns = [
    {
      title: '申请编号',
      dataIndex: 'applyNo',
      width: 100,
    },
    {
      title: '申请时间',
      dataIndex: 'applyTime',
      width: 120,
    },
    {
      title: '处理状态',
      dataIndex: 'currentAuditNode',
      width: 80,
      render: (text: string) => {
        if (text === '0') return '企业申请';
        if (text === '1') return '主管部门初审';
        if (text === '2') return '政策兑现办审核';
        if (text === '3') return '主管部门复审';
        if (text === '4') return '园区终审';
        if (text === '5') return '财政终审';
        if (text === '6') return '园区公示拨付';
        if (text === '7') return '已拨付';
        return '中止';
      },
    },
    {
      title: '处理时间',
      dataIndex: 'currentAuditTime',
      width: 120,
    },
  ];

  const onFinish = (values: any) => {
    const { applicationDate, applyNo } = values;
    setSearchCondition({
      applyStartTime: applicationDate?.length
        ? moment(applicationDate[0]).format('YYYY-MM-DD HH:mm:ss')
        : undefined,
      applyEndTime: applicationDate?.length
        ? moment(applicationDate[1]).format('YYYY-MM-DD HH:mm:ss')
        : undefined,
      applyNo,
      // page: 1,
      // size: 10,
    });
  };
  return (
    <ConfigProvider locale={zhCN}>
      <div className={styles.ResultPublicityWrapper}>
        <div className={styles.ResultPublicityTitle}>
          <div className={styles.titleLeft}>
            <div className={styles.sideShortBar}></div>
            <div className={styles.titleText}>结果公示</div>
          </div>
          <div className={styles.titleRight}>
            <Form {...layout} className={styles.ResultPublicityForm} onFinish={onFinish}>
              <Row>
                <Col>
                  <Form.Item label="申请时间" name="applicationDate">
                    <RangePicker
                      showTime={{
                        hideDisabledOptions: true,
                        defaultValue: [
                          moment('00:00:00', 'HH:mm:ss'),
                          moment('11:59:59', 'HH:mm:ss'),
                        ],
                      }}
                      format="YYYY-MM-DD HH:mm:ss"
                    />
                  </Form.Item>
                </Col>
                <Col span={1}></Col>
                <Col>
                  <Form.Item label="申请编号" name="applyNo">
                    <Input className={styles.SearchInput} placeholder="请输入申请编号" />
                  </Form.Item>
                </Col>
                <Col span={2}>
                  <Form.Item>
                    <Button
                      className={styles.SearchInput}
                      type="primary"
                      htmlType="submit"
                      icon={<SearchOutlined />}
                    />
                  </Form.Item>
                </Col>
              </Row>
            </Form>
          </div>
        </div>
        <div className={styles.ResultPublicityTable}>
          <Table
            columns={columns}
            dataSource={resultPublicityData}
            size="middle"
            scroll={{ y: 375 }}
            pagination={false}
          />
        </div>
      </div>
    </ConfigProvider>
  );
};

export default ResultPublicityTable;
